# 58. 围棋的气
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const maxSide = 18;
rl.on('line', function(line) {
let locBlacks = parseCoor(line);
rl.on('line', function(line) {
let locWhites = parseCoor(line);
console.log(counting(locBlacks, locWhites) + ' ' + counting(locWhites, locBlacks));
});
});
function parseCoor(input) {
return input.split(' ').map(Number);
}
function counting(alias, enemy) {
let count = new Set();
for(let i=0; i<alias.length; i+=2) {
let x = alias[i];
let y = alias[i+1];
let pos = x + '_' + y;
count.add(pos);
if (x > 0) {
count.add((x-1) + '_' + y);
}
if (x < maxSide) {
count.add((x+1) + '_' + y);
}
if (y > 0) {
count.add(x + '_' + (y-1));
}
if (y < maxSide) {
count.add(x + '_' + (y+1));
}
}
let res = count.size;
for(let i=0; i<enemy.length; i+=2) {
let pos = enemy[i] + '_' + enemy[i+1];
if (count.has(pos)) {
res--;
}
}
return res - alias.length/2;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
← 57. 机场航班调度 59. 小华地图寻宝 →